﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ServerSettingPanel : MonoBehaviour
{
    public InputField ServerIP,ServerPort;
    public Button connectButton;
    public Text connectButtonText;

    private void Awake()
    {
        connectButton.onClick.AddListener(OnConnectButtonClick);
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }

    void Update()
    {
        switch (Singleton<ChatClient>.GetInstance().CurrentState)
        {
            case ClientState.Unstarted:
                connectButtonText.text = "未连接服务器(点击连接)";
                break;
            case ClientState.WaitRcving:
                connectButtonText.text = "服务运行中(点击销毁)";
                break;
            default:
                break;
        }

    }
    void OnConnectButtonClick()
    {
        if (Singleton<ChatClient>.GetInstance().CurrentState == ClientState.Unstarted)
        {
            Singleton<ChatClient>.GetInstance().ServerIp = ServerIP.text;
            Singleton<ChatClient>.GetInstance().ServerPort = Convert.ToInt32(ServerPort.text);
            Singleton<ChatClient>.GetInstance().Start();
        }
        else if (Singleton<ChatClient>.GetInstance().CurrentState == ClientState.WaitRcving)
            Singleton<ChatClient>.GetInstance().Destory();
        else
            return;

    }
}
